package com.master5.grocerylist;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.google.appengine.api.rdbms.AppEngineDriver;

public class ConnectionHelper {
	private static String url;
	private static ConnectionHelper instance;

	private ConnectionHelper() {
		url = "jdbc:google:rdbms://grocerylistapp2:grocerylistapp3/grocerylist";
	}

	public static Connection getConnection() {
		if (instance == null) {
			instance = new ConnectionHelper();
		}
		try {
			DriverManager.registerDriver(new AppEngineDriver());
			return DriverManager.getConnection(url, "yigit353", "1960YIG90q");
		} catch (SQLException e) {
			return null;
		} 
	}

	public static void close(Connection connection) {
		try {
			if (connection != null) {
				connection.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}